package io.lvdaxian.mybatis05.datasource.druid;

import com.alibaba.druid.pool.DruidDataSource;
import io.lvdaxian.mybatis05.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * 德鲁伊 数据源 factory
 *
 * @author lihh
 */
public class DruidDataSourceFactory implements DataSourceFactory {
  private Properties props;
  
  @Override
  public DataSource getDataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(props.getProperty("driver"));
    dataSource.setUrl(props.getProperty("url"));
    dataSource.setUsername(props.getProperty("username"));
    dataSource.setPassword(props.getProperty("password"));
    return dataSource;
  }
  
  @Override
  public void setProperties(Properties props) {
    this.props = props;
  }
}
